#! /bin/sh
#
# chkconfig: 2345 92 29
# description: XRelayer HTTP proxy daemon
#
. /etc/rc.d/init.d/functions

INSTALL_PATH=@CMAKE_INSTALL_PREFIX@/xrelayer
XRELAYER=${INSTALL_PATH}/xrelayer

case "$1" in
start)
	echo -n $"Starting xrelayer: "
	if [ -e /var/lock/subsys/xrelayer ]; then
		if [ -e /var/run/xrelayer.pid ] && [ -e /proc/`cat /var/run/xrelayer.pid` ]; then
			echo -n $"cannot start xrelayer: xrelayer is already running."
			failure $"cannot start xrelayer: xrelayer is already running."
			echo
			exit 1
		fi
	fi
	$XRELAYER && success || failure
	RETVAL=$?
	[ "$RETVAL" = 0 ] && touch /var/lock/subsys/xrelayer
	[ "$RETVAL" = 0 ] && echo `pidof $XRELAYER` > /var/run/xrelayer.pid
	echo
	;;
stop)
	echo -n $"Stopping xrelayer: "
	if [ -n "`pidfileofproc $XRELAYER`" ] ; then
		killproc $XRELAYER
	else
		failure $"Stopping xrelayer"
	fi
	RETVAL=$?
	[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/xrelayer
	echo
	;;
*)
	echo "Usage: $0 {start|stop}"
	exit 1
esac
exit 0
#######################################################

